import { Component, director, instantiate, Prefab, _decorator } from "cc";
import { EventDispatcher } from "../../../ngame/util/EventDispatcher";
import GameConst, { UIConfig, UI_VIEW } from "../../GameConst";
import { ProjectionManage } from "../../manage/ProjectionManage";
import { ISoldierController } from "../role/ISoldierController";
import { CardController } from "./卡牌/CardController";
import { CardsController } from "./卡牌/CardsController";

const { ccclass, property,executeInEditMode } = _decorator;

@ccclass('UIController')
export class UIController extends Component {

    scaleScene:boolean = false;

    //卡牌
    @property({ type:Prefab, displayName:"卡牌" })
    card:Prefab = null;

    //点击缩放场景
    clickScaleScene(){

        let projection = director.getScene().getComponentInChildren(ProjectionManage);
        if(!projection) return;

        if(this.scaleScene)
            projection.hcamera = projection.cameraMaxH;
        else
            projection.hcamera = projection.cameraDefaultH;

        this.scaleScene = !this.scaleScene;

    }
    

    //点击招募士兵
    clickRecruit(){
        
        EventDispatcher.getIns().emit(GameConst.UI_TOUCH.CLICK_RECRUIT)

    }

    //添加卡牌
    clickAddCard(){

        director.getScene().getComponentInChildren(CardsController).addCard(instantiate(this.card).getComponent(CardController));

    }

    //打开背包
    clickOpenBackPack(){

        // UI_VIEW.POPUP.show(UIConfig.Tips,"打开背包");
        UI_VIEW.POPUP.show(UIConfig.BackPack);

    }

    //点击攻击
    clickAttack(){

        EventDispatcher.getIns().emit(GameConst.UI_TOUCH.CLICK_ATTACK)

    }

}
